package com.show.service.grid_owner;

import com.show.dao.grid_owner.GridOwnerRepositoty;
import com.show.dto.grid_owner.GridOwner;
import com.show.util.QueryUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

/**
 * Created by yxd on 2018/1/30.
 */
@Service
@Transactional
public class GridOwnerService {
    @Autowired
    private GridOwnerRepositoty gridOwnerRepositoty;
    @Autowired
    private QueryUtil queryUtil;

    /**
     * 新增网格长
     * params
     * @author yxd
     * @date 2018-02-08 10:13
     */
    public GridOwner insert(GridOwner gridOwner){
        return gridOwnerRepositoty.saveAndFlush(gridOwner);
    }

    /**
     * 删除网格长
     * params
     * @author yxd
     * @date 2018-02-08 10:13
     */
    public void delete(int gridId){
        gridOwnerRepositoty.delete(String.valueOf(gridId));
    }

    /**
     * 根据mpId 查询gridId
     * @param empId
     * @author sure
     * @return
     */
    public List<GridOwner> queryByEmpId (Integer empId){
        String sql = "SELECT * FROM `grid_owner` where emp_id = " + empId ;
        if(queryUtil.query(sql,GridOwner.class) != null && queryUtil.query(sql,GridOwner.class).size()>0){
            return queryUtil.query(sql,GridOwner.class);
        }
       return null;
    }
}
